package com.ls.herostory.cmdhandler;

import com.ls.herostory.channel.handler.BroadCast;
import com.ls.herostory.session.Session;
import com.ls.herostory.session.SessionUtil;
import com.ls.herostory.msg.GameMsgProtocol;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * @author liangsu
 * @version v1.0
 * @Description
 * @Date 2020/10/12 9:14
 * @since
 */
public class UserEntryCmdHandler implements CmdHandler<GameMsgProtocol.UserEntryCmd> {

    public void handleCmd(ChannelHandlerContext ctx, GameMsgProtocol.UserEntryCmd cmd) {
        Session session = SessionUtil.getSession((NioSocketChannel) ctx.channel());
        if(session == null){
            return;
        }

        GameMsgProtocol.UserEntryResult userEntryResult = GameMsgProtocol.UserEntryResult.newBuilder()
                .setUserId(session.getUserId())
                .setHeroAvatar(session.getHeroAvatar())
                .build();

        // 广播
        BroadCast.cast(userEntryResult);
    }

}
